package com.mingyuan.library.infra.common.event.config;

import com.mingyuan.library.domain.common.event.DomainEvents;
import com.mingyuan.library.infra.common.event.publisher.MeteredDomainEventPublisher;
import com.mingyuan.library.infra.common.event.publisher.JustForwardDomainEventPublisher;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 领域事件配置
 */
@Configuration
public class DomainEventsConfig {

    /**
     * 领域事件发布
     * @author yangzk
     * @param applicationEventPublisher 应用事件发布
     * @param meterRegistry 注册事件
     * @date 2024/1/5 14:20
     *
     **/
    @Bean
    DomainEvents domainEvents(ApplicationEventPublisher applicationEventPublisher, MeterRegistry meterRegistry) {
        return new MeteredDomainEventPublisher(new JustForwardDomainEventPublisher(applicationEventPublisher), meterRegistry);
    }
}
